package com.stdio.tools;

import java.util.ArrayList;

import com.stdio.tools.HanziToPinyin.Token;


public class StringMethod {
	
	public static final int TYPE_NONE = 0;
	public static final int TYPE_CHINESE = 1;
	public static final int TYPE_ENGLISH = 2;
	public static final int TYPE_NUMBER = 3;
	public static final int TYPE_SYMBOL = 4;
	
	public static final int TYPE_NORMAL = 0;
	public static final int TYPE_UPPER = 1;
	public static final int TYPE_LOWER = 2;
	
	//Check the first character's type which in specify string 
	public static int checkStringFirstCharType(String strValue) {
		if(strValue.length() == 0) {
			return TYPE_NONE;
		}
		
		if(strValue.trim().length() == 0) {
			return TYPE_NONE;
		}
		
		char c = strValue.trim().charAt(0);
		
		if(c >= 0 && c <= 9) {
			return TYPE_NUMBER;
		}
		
		
		if((c >= 'A' && c < 'Z') || (c >= 'a' && c < 'z')) {
			return TYPE_ENGLISH;
		}
		
		if(Character.isLetter(c)) {
			return TYPE_CHINESE;
		} 
		
		return TYPE_SYMBOL;
	}
	
	//get the first char in upcase from the specify string
	public static char getStringFirstCharacter(String strValue){
		
		return 'A';
	}
	
	//get character from the given string whatever the string is chars or chinese or symbol
	public static String getCharacterFromString(String strValue, int type) {
		ArrayList<Token> tokens = HanziToPinyin.getInstance().get(strValue);
		StringBuilder sb = new StringBuilder();
		if(tokens != null && tokens.size() > 0)
		{
			for(Token token : tokens) 
			{
				if(Token.PINYIN == token.type) {
					sb.append(token.target);
				} else {
					sb.append(token.source);
				}
			}
		}
		
		if(type == TYPE_UPPER){
			return sb.toString().toUpperCase();
		} else if(type == TYPE_LOWER) {
			return sb.toString().toLowerCase();
		} else {
			return sb.toString();
		}
	}
	
	public static boolean isPhoneNumber(String strValue) {
		return strValue.matches("^(13|15|18)\\d{9}$");
	}
	
}
